package com.mybatisflex.demo.service.impl;

import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.demo.entity.Account;
import com.mybatisflex.demo.mapper.AccountMapper;
import com.mybatisflex.demo.service.AccountService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 王帅
 * @since 2023-08-13
 */
@Service
@UseDataSource("ds2")
@SuppressWarnings("all")
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {

    @Override
    @UseDataSource("ds3")
    public List<Account> list() {
        try {
//            FlexDataSource dataSource = FlexGlobalConfig.getDefaultConfig().getDataSource();
//            dataSource.removeDatasource("ds5");
            DataSourceKey.use("ds1");
            return super.list();
        } finally {
            DataSourceKey.clear();
        }
    }

    @Override
    public List<Account> list(QueryWrapper query) {
//        Account loginUser = LoginManager.getLoginUser();
//        query.and(ACCOUNT.DEPT_ID.eq(loginUser.getDeptId()));
        return super.list(query);
    }

}